﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OfficeOpenXml;
using System.Data;
using System.IO;
using OfficeOpenXml.Drawing;
using System.Drawing;

namespace EPlusReport
{
    /// <summary>
    /// EPPlus Reporting
    /// </summary>
    public class EPReport
    {

        public delegate void export_event(object[] args);
        public event export_event export_processing;
        void OnExportProcessing(object[] args)
        {
            if (export_processing != null)
            {
                export_processing.Invoke(args);
            }
        }

        /// <summary>
        /// Export DataSet To Excel
        /// </summary>
        /// <param name="excelFileName"></param>
        /// <param name="srcDataTable"></param>
        /// <param name="sPWD"></param>
        public void export(string excelFileName, System.Data.DataSet ds, string Pwd, bool isReadonly)
        {
            ExcelPackage ExcelPkg = new ExcelPackage();
            int iSheet = 0;
            foreach (System.Data.DataTable srcDataTable in ds.Tables)
            {
                iSheet++;
                ExcelWorksheet wsSheet1 = ExcelPkg.Workbook.Worksheets.Add(string.Concat("Sheet", iSheet));
                int irow = 1;
                for (int i = 0; i < srcDataTable.Columns.Count; i++)
                {
                    using (ExcelRange Rng = wsSheet1.Cells[irow, i + 1])
                    {
                        Rng.Value = srcDataTable.Columns[i].ColumnName;
                        Rng.Style.Font.Size = 12;
                        Rng.Style.Font.Bold = true;
                        Rng.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                        Rng.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.AliceBlue);
                        //Rng.Style.Font.Italic = true;
                    }
                }
                foreach (DataRow dr in srcDataTable.Rows)
                {
                    irow++;
                    for (int i = 0; i < srcDataTable.Columns.Count; i++)
                    {
                        using (ExcelRange Rng = wsSheet1.Cells[irow, i + 1])
                        {
                            Rng.Value = pub.FieldValue(dr[i]);
                            Rng.Style.Font.Size = 12;
                        }
                    }
                }
                wsSheet1.Cells.AutoFitColumns();
                wsSheet1.Protection.IsProtected = isReadonly;
                if (isReadonly)
                {
                    wsSheet1.Protection.SetPassword(DateTime.Now.ToString("yyyyMMdd"));
                }
                wsSheet1.Protection.AllowSelectLockedCells = true;
            }

            ExcelPkg.SaveAs(new FileInfo(excelFileName), Pwd);
        }

        /// <summary>
        /// Export DataTable To Excel
        /// </summary>
        /// <param name="excelFileName"></param>
        /// <param name="srcDataTable"></param>
        /// <param name="sPWD"></param>
        public void export(string excelFileName, System.Data.DataTable dt, string Pwd, bool isReadonly)
        {
            if (File.Exists(excelFileName)) File.Delete(excelFileName);
            ExcelPackage ExcelPkg = new ExcelPackage();
            int iSheet = 0;
            System.Data.DataTable srcDataTable = dt;
            {
                iSheet++;
                ExcelWorksheet wsSheet1 = ExcelPkg.Workbook.Worksheets.Add(string.Concat("Sheet", iSheet));
                int irow = 1;
                for (int i = 0; i < srcDataTable.Columns.Count; i++)
                {
                    using (ExcelRange Rng = wsSheet1.Cells[irow, i + 1])
                    {
                        Rng.Value = srcDataTable.Columns[i].ColumnName;
                        Rng.Style.Font.Size = 12;
                        Rng.Style.Font.Bold = true;
                        Rng.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                        Rng.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.AliceBlue);
                        //Rng.Style.Font.Italic = true;
                    }

                }
                foreach (DataRow dr in srcDataTable.Rows)
                {
                    irow++;
                    for (int i = 0; i < srcDataTable.Columns.Count; i++)
                    {
                        using (ExcelRange Rng = wsSheet1.Cells[irow, i + 1])
                        {
                            string dtype = dr[i].GetType().Name.ToLower();
                            if ("short,int,int32,float,double,decimal".Contains(dtype))
                            {
                                Rng.Value = dr[i];
                            }
                            else
                            {
                                Rng.Value = pub.FieldValue(dr[i]);
                            }
                            Rng.Style.Font.Size = 12;
                        }
                    }
                }

                wsSheet1.Cells.AutoFitColumns();

                if (isReadonly)
                {
                    wsSheet1.Protection.IsProtected = isReadonly;
                    wsSheet1.Protection.SetPassword(DateTime.Now.ToString("yyyyMMdd"));
                }
                wsSheet1.Protection.AllowSelectLockedCells = true;
            }

            ExcelPkg.SaveAs(new FileInfo(excelFileName), Pwd);
        }


        /// <summary>
        /// Save As Office DataTable To Excel
        /// Detail:{field} ; Head : {!field} ; GroupBy:[!group=field1,field2] / value=[field,other field=value]
        /// </summary>
        /// <param name="excelFileName"></param>
        /// <param name="srcDataTable"></param>
        /// <param name="sPWD"></param>
        public void saveAs(string excelFileName, string Pwd, string toFile, string newPwd, bool isReadonly)
        {
            ExcelPackage ExcelPkg = null;
            if (string.IsNullOrEmpty(Pwd))
            {
                ExcelPkg = new ExcelPackage(new FileInfo(excelFileName));
            }
            else
            {
                ExcelPkg = new ExcelPackage(new FileInfo(excelFileName), Pwd);
            }
            foreach (var ws in ExcelPkg.Workbook.Worksheets)
            {
                ws.Protection.IsProtected = isReadonly;
            }
            ExcelPkg.SaveAs(new FileInfo(toFile), newPwd);
        }

        public System.Data.DataTable import(string excelFileName, string Pwd, string shName, bool noHeader)
        {

            var package = new ExcelPackage(new FileInfo(excelFileName), Pwd);
            ExcelWorksheet workSheet = null;
            for (int i = 1; i <= package.Workbook.Worksheets.Count; i++)
            {
                if (i.ToString() == shName
                    || package.Workbook.Worksheets[i].Name == shName
                    )
                {
                    workSheet = package.Workbook.Worksheets[i];
                    break;
                }
            }
            System.Data.DataTable dt = null;
            if (workSheet != null)
            {
                dt = new System.Data.DataTable("table");
                for (int j = workSheet.Dimension.Start.Column;
                         j <= workSheet.Dimension.End.Column;
                         j++)
                {
                    if (noHeader)
                    {
                        dt.Columns.Add(string.Concat("F", j), "".GetType());
                    }
                    else
                    {
                        dt.Columns.Add(workSheet.Cells[1, j].Value.ToString(), "".GetType());
                    }
                }

                for (int i = workSheet.Dimension.Start.Row;
                      i <= workSheet.Dimension.End.Row;
                   i++)
                {
                    DataRow dr = dt.NewRow();
                    int ic = 0;
                    for (int j = workSheet.Dimension.Start.Column;
                             j <= workSheet.Dimension.End.Column;
                             j++)
                    {
                        //object cellValue = workSheet.Cells[i, j].Value;
                        dr[ic] = pub.FieldValue(workSheet.Cells[i, j].Value);
                        ic++;
                    }
                    dt.Rows.Add(dr);
                }
            }
            package.Dispose();
            return dt;
        }

        public void report(string excelFileName, string Pwd, string shName, System.Data.DataTable dtData, string outFile)
        {
            report(excelFileName, Pwd, shName, dtData, outFile, "", false);
        }

        ExcelPackage package = null;
        ExcelWorksheet workSheet = null;

        /// <summary>
        /// Create Report With Template ()
        /// </summary>
        /// <param name="excelFileName"></param>
        /// <param name="Pwd"></param>
        /// <param name="shName"></param>
        /// <param name="dtData"></param>
        /// <param name="outFile"></param>
        /// <param name="newPwd"></param>
        /// <param name="isProtect"></param>
        public void report(string excelFileName, string Pwd, string shName, System.Data.DataTable dtData, string outFile, string newPwd, bool isProtect)
        {
            System.IO.File.Copy(excelFileName, outFile, true);
            if (string.IsNullOrEmpty(Pwd))
            {
                package = new ExcelPackage(new FileInfo(outFile));
            }
            else
            {
                package = new ExcelPackage(new FileInfo(outFile), Pwd);
            }

            foreach (int i in getSheet(shName))
            {
                setSheet(i);
                autoDetectExp(i);
                update(dtData);
                if (isProtect)
                {
                    workSheet.Protection.IsProtected = true;
                    workSheet.Protection.SetPassword(DateTime.Now.ToString("yyyyMMdd"));
                    workSheet.Protection.AllowSelectLockedCells = true;
                }
            }

            if (string.IsNullOrEmpty(newPwd))
            {
                package.Save();
            }
            else
            {
                package.Save(newPwd);
            }
            package.Dispose();
        }


        public void setSheet(int i)
        {
            workSheet = package.Workbook.Worksheets[i];
        }

        private int[] getSheet(string sheetname)
        {
            List<int> lst = new List<int>();
            if (sheetname == "*")
            {
                for (int i = 0; i < package.Workbook.Worksheets.Count; i++)
                {
                    lst.Add(i + 1);
                }
            }
            else
            {
                if (string.IsNullOrEmpty(sheetname)) sheetname = "1";
                foreach (string sh in sheetname.ToUpper().Split(','))
                {
                    for (int i = 1; i <= package.Workbook.Worksheets.Count; i++)
                    {
                        if (package.Workbook.Worksheets[i].Name.ToUpper() == sh
                            || i.ToString() == sh)
                        {
                            lst.Add(i);
                            break;
                        }
                    }
                }

                if (lst.Count == 0)
                {
                    lst.Add(1);
                }
            }
            return lst.ToArray();
        }


        public void autoDetectExp(int isheet)
        {
            setSheet(isheet);
            int ii1 = 0;
            int ii2 = 0;

            var rn = workSheet.Dimension.End; //.Row + 1, workSheet.Dimension.End.Column + 1];

            for (int r = 1; r <= rn.Row; r++)
            {
                if (r > 10) break;
                for (int c = 1; c <= rn.Column; c++)
                {
                    if (c > 50) break; //if 50 column no data then skip
                    string val = string.Concat(workSheet.Cells[r, c].Text);
                    if (string.IsNullOrEmpty(val)) continue;
                    ii1 += pub.Matches(val, "{*}").Length > 0 ? 1 : 0;
                    ii2 += pub.Matches(val, "[*]").Length > 0 ? 1 : 0;
                }
            }

            if (ii1 > 1)
            {
                matchDetail = "{*}";
                matchHead = "{!*}";
            }
        }

        public string matchHead = "#[*]";
        public string matchDetail = "![*]";

        public void SetCellValue(ExcelRange cell, object v)
        {
            if (v == null) return;

            if (v.GetType() == int.MinValue.GetType())
            {
                cell.Style.Numberformat.Format = "#,##0";
            }
            else
                if (v.GetType() == double.MinValue.GetType()
                    || v.GetType() == float.MinValue.GetType()
                    )
                {
                    cell.Style.Numberformat.Format = "#,##0.00";
                }

            if (v.GetType() != DBNull.Value.GetType())
            {
                cell.Value = v;
            }
        }

        /// <summary>
        /// Create Report With Template ()
        /// </summary>
        /// <param name="excelFileName"></param>
        /// <param name="Pwd"></param>
        /// <param name="shName"></param>
        /// <param name="dtData"></param>
        /// <param name="outFile"></param>
        /// <param name="newPwd"></param>
        /// <param name="isProtect"></param>
        public void report(string excelFileName, string Pwd, string shName, System.Data.DataSet dsData, string outFile, string newPwd, bool isProtect)
        {
            System.IO.File.Copy(excelFileName, outFile, true);
            if (string.IsNullOrEmpty(Pwd))
            {
                package = new ExcelPackage(new FileInfo(outFile));
            }
            else
            {
                package = new ExcelPackage(new FileInfo(outFile), Pwd);
            }

            int[] isheets = getSheet(shName);
            for (int i = 0; i < isheets.Length; i++)
            {
                if (dsData.Tables.Count <= i) break;
                setSheet(isheets[i]);
                autoDetectExp(isheets[i]);
                if (dsData.Tables.Count > i)
                {
                    update(dsData.Tables[i]);
                }

                if (isProtect)
                {
                    workSheet.Protection.IsProtected = true;
                    workSheet.Protection.SetPassword(DateTime.Now.ToString("yyyyMMdd"));
                    workSheet.Protection.AllowSelectLockedCells = true;
                }
            }

            if (string.IsNullOrEmpty(newPwd))
            {
                package.Save();
            }
            else
            {
                package.Save(newPwd);
            }
            package.Dispose();
        }

        public void update(DataTable dtData)
        {
            string sGroupBy = "";
            string sOrderBy = "";
            string sFilter = "";

            if (workSheet != null)
            {
                int ibodyStart = 0;
                int ibodyEnd = 0;
                DataRow drhead = (dtData.Rows.Count > 0) ? dtData.Rows[0] : dtData.NewRow();
                object[,] body = new object[workSheet.Dimension.End.Row + 1, workSheet.Dimension.End.Column + 1];

                //check header & file structor (group)
                for (int i = workSheet.Dimension.Start.Row;
                      i <= workSheet.Dimension.End.Row;
                   i++)
                {
                    //avoid too much rows
                    if (ibodyEnd > 0 && i > ibodyEnd + 5) break;

                    for (int j = workSheet.Dimension.Start.Column;
                             j <= workSheet.Dimension.End.Column;
                             j++)
                    {

                        string tv = workSheet.Cells[i, j].Text;
                        var t = GetField(workSheet.Cells[i, j].Text, matchHead);
                        if (!string.IsNullOrEmpty(t))
                        {
                            string fn = t.ToLower();
                            if (fn.StartsWith("group="))
                            {
                                sGroupBy = fn.Split('=')[1].Trim();
                                sOrderBy = sGroupBy;
                                workSheet.Cells[i, j].Value = "";
                            }
                            else
                                if (fn.StartsWith("filter="))
                                {
                                    sFilter = fn.Split('=')[1].Trim();
                                    workSheet.Cells[i, j].Value = "";
                                }
                                else
                                    if (fn.StartsWith("orderby="))
                                    {
                                        sOrderBy = fn.Split('=')[1].Trim();
                                        workSheet.Cells[i, j].Value = "";
                                    }
                                    else
                                    {
                                        object v = SetValue(tv, matchHead, drhead);
                                        if (!UpdatePic(string.Concat(v), workSheet.Cells[i, j]))
                                        {
                                            workSheet.Cells[i, j].Value = v;
                                            body[i, j] = string.Concat(v);
                                        }
                                    }
                        }
                        else
                            if (!string.IsNullOrEmpty(GetField(tv, matchDetail)))
                            {
                                body[i, j] = string.Concat(tv);
                                if (ibodyStart == 0) ibodyStart = i;
                                ibodyEnd = i;
                            }
                    }
                }

                dtData.DefaultView.Sort = sOrderBy;
                dtData.DefaultView.RowFilter = sFilter;

                //update body detail
                int irow = ibodyStart;
                string sGroupValue = "";
                if (!string.IsNullOrEmpty(sGroupBy))
                {
                    if (dtData.Rows.Count > 0)
                    {
                        sGroupValue = GetRowValue(sGroupBy, dtData.DefaultView[0].Row);
                    }
                }

                for (int r = 0; r < dtData.DefaultView.Count; r++)
                {
                    DataRow dr = dtData.DefaultView[r].Row;

                    if (string.IsNullOrEmpty(sGroupBy))
                    {
                        if (r > 0)
                        {
                            for (int i = 0; i <= ibodyEnd - ibodyStart; i++)
                            {
                                workSheet.InsertRow(irow + (ibodyEnd - ibodyStart) + 1, 1, ibodyStart + i);
                                irow++;
                            }
                        }

                        for (int i = 0; i <= ibodyEnd - ibodyStart; i++)
                        {

                            for (int j = workSheet.Dimension.Start.Column;
                                j <= workSheet.Dimension.End.Column;
                                j++)
                            {
                                if (body[ibodyStart + i, j] != null)
                                {
                                    SetCellValue(workSheet.Cells[irow + i, j], SetValue(body[ibodyStart + i, j], matchDetail, dr));
                                }
                            }
                        }
                    }
                    else
                    {
                        if (GetRowValue(sGroupBy, dr) != sGroupValue)
                        {
                            for (int i = 0; i <= ibodyEnd - ibodyStart; i++)
                            {
                                workSheet.InsertRow(irow + (ibodyEnd - ibodyStart) + 1, 1, ibodyStart + i);

                                for (int j = workSheet.Dimension.Start.Column;
                                     j <= workSheet.Dimension.End.Column;
                                      j++)
                                {
                                    if (body[ibodyStart + i, j] != null)
                                    {
                                        //clear formular
                                        SetCellValue(workSheet.Cells[irow, j], SetValue(workSheet.Cells[irow, j].Value, matchDetail, null));
                                        workSheet.Cells[irow + 1 + (ibodyEnd - ibodyStart) + i, j].Value = body[ibodyStart + i, j];
                                    }
                                }
                                irow++;
                            }
                            sGroupValue = GetRowValue(sGroupBy, dr);

                        }

                        for (int i = 0; i <= ibodyEnd - ibodyStart; i++)
                        {
                            for (int j = workSheet.Dimension.Start.Column;
                                j <= workSheet.Dimension.End.Column;
                                j++)
                            {
                                if (body[ibodyStart + i, j] != null)
                                {
                                    SetCellValue(workSheet.Cells[irow + i, j], SetValue(workSheet.Cells[irow + i, j].Value, matchDetail, dr));
                                }
                            }
                        }
                    }
                }

                //clear formular
                for (int i = 0; i <= ibodyEnd - ibodyStart; i++)
                {
                    for (int j = workSheet.Dimension.Start.Column;
                         j <= workSheet.Dimension.End.Column;
                          j++)
                    {
                        if (body[ibodyStart + i, j] != null)
                        {
                            SetCellValue(workSheet.Cells[irow + i, j], SetValue(workSheet.Cells[irow + i, j].Value, matchDetail, null));
                        }
                    }
                }

            }

        }

        private void AddImage(Bitmap image, ExcelRange rn)
        {
            //How to Add a Image using EP Plus
            //Bitmap image = new Bitmap(filePath);
            ExcelPicture picture = null;
            if (image != null)
            {
                picture = workSheet.Drawings.AddPicture("pic" + rn.Start.Row.ToString() + rn.Start.Column.ToString(), image);
                picture.From.Column = rn.Start.Column;
                picture.From.Row = rn.Start.Row;
                //picture.From.ColumnOff = Pixel2MTU(2); //Two pixel space for better alignment
                //picture.From.RowOff = Pixel2MTU(2);//Two pixel space for better alignment
                //picture.SetSize(100, 100);
            }
        }

        private bool UpdatePic(string val, ExcelRange rnn)
        {
            bool isfind = false;
            if (val.ToUpper().IndexOf("&") > 0)
            {
                try
                {
                    Image bmp = null;
                    string imgfile = System.IO.Path.GetTempFileName() + ".jpg";
                    string ret = val.Split('&')[0];
                    string[] codes = (val.Split('&')[1] + ",,,,,,").Split(',');
                    string codetype = codes[0].ToUpper();
                    if (codetype == "F")
                    {
                        imgfile = ret;
                    }
                    else
                        if (codetype == "QR")
                        {
                            if (!string.IsNullOrEmpty(codes[1])
                                && System.IO.File.Exists(codes[1]))
                            {
                                //with logo
                                bmp = QRCODE.DrawCode(ret, codes[1]);
                            }
                            else
                            {
                                bmp = QRCODE.DrawCode(ret, "");
                            }
                        }
                        else
                            if (codetype == "BR")
                            {
                                barcode.Code128 br = new barcode.Code128();
                                //if (pub.IsNumber(codes[1]) && pub.IsNumber(codes[2]))
                                //{
                                //    bmp =  QRCODE.DrawBarcode(ret, int.Parse(codes[1]), int.Parse(codes[2]));
                                //}
                                //else
                                //{
                                //    bmp = QRCODE.DrawBarcode(ret, 0, 0);
                                //}
                                bmp = new Bitmap(br.GetCodeImage(ret));
                            }

                    if (bmp != null)
                    {
                        AddImage(new Bitmap(bmp), rnn);
                        //ExcelPicture pic = workSheet.Drawings.AddPicture(string.Concat("pic", rnn.Start.Row, "_", rnn.Start.Column), bmp);
                        //pic.SetPosition(rnn.Start.Row,0,rnn.Start.Column,0);
                        isfind = true;
                    }
                }
                catch (Exception exPic)
                {
                    Console.WriteLine(exPic.Message);
                }
            }
            return isfind;
        }

        public string GetRowValue(string fields, DataRow dr)
        {
            string ss = "";
            foreach (string s in fields.Split(','))
            {
                if (dr.Table.Columns.Contains(s))
                {
                    ss += string.Concat(dr[s]);
                }
            }
            return ss;
        }

        private string GetField(string t, string matchStr)
        {
            if (string.IsNullOrEmpty(t)) return t;
            string s = null;
            foreach (string exp in pub.Matches(t, matchStr))
            {
                string[] aa = matchStr.Split('*');
                s = exp.Substring(aa[0].Length, exp.Length - aa[1].Length - aa[0].Length);
                break;
            }
            return s;
        }

        public object SetValue(object v, string matchStr, DataRow dr)
        {
            string ss = string.Concat(v);
            bool isfound = false;
            foreach (string exp in Matches(ss, matchStr))
            {
                isfound = true;
                string f = GetField(exp, matchStr);
                string[] ff = (f + ",,,,").Split(',');
                if (dr == null)
                {
                    if (ss == exp && !string.IsNullOrEmpty(ff[2]))
                    {
                        try
                        {
                            if (ff[2].Contains("."))
                            {
                                return double.Parse(ff[2]);
                            }
                            else
                            {
                                return int.Parse(ff[2]);
                            }
                        }
                        catch
                        {
                            return ss.Replace(exp, ff[2]);
                        }
                    }
                    ss = ss.Replace(exp, ff[2]);
                    continue;
                }

                string fmt = ff[3];
                if ((ff[0].StartsWith("sum(")
                     || ff[0].StartsWith("avg(")
                     || ff[0].StartsWith("count(")
                    ) && ff[0].EndsWith(")"))
                {
                    try
                    {
                        if (ss == exp)
                        {
                            return pub.FieldValueObj(dr.Table.Compute(ff[0], ff[1]), fmt);
                        }
                        else
                        {
                            ss = ss.Replace(exp, pub.FieldValue(dr.Table.Compute(ff[0], ff[1]), fmt));
                        }
                    }
                    catch
                    {
                        ss = "#error";
                    }
                }
                else
                {
                    if (ff[0].Contains("=") && dr.Table.Columns.Contains(ff[1]))
                    {
                        string ff0 = ff[0];
                        ff[0] = ff[1];
                        ff[1] = ff0;
                    }

                    if (dr.Table.Columns.Contains(ff[0]))
                    {
                        if (ff[1].Contains("="))
                        {
                            string[] fff = ff[1].Split('=');
                            if (dr.Table.Columns.Contains(fff[0]))
                            {
                                if (string.Concat(dr[fff[0]]).ToLower() == fff[1].ToLower())
                                {
                                    if (ss == exp)
                                    {
                                        return pub.FieldValueObj(dr[ff[0]], fmt);
                                    }
                                    else
                                    {
                                        ss = ss.Replace(exp, pub.FieldValue(dr[ff[0]], fmt));
                                    }
                                }
                            }
                            else
                            {
                                ss = ss.Replace(exp, "");
                            }
                        }
                        else
                        {
                            if (ss == exp || string.IsNullOrEmpty(ss))
                            {
                                return pub.FieldValueObj(dr[ff[0]], fmt);
                            }
                            else
                            {
                                ss = ss.Replace(exp, pub.FieldValue(dr[ff[0]], fmt));
                            }
                        }
                    }
                }
            }
            if (!isfound)
            {
                return v;
            }
            else
            {
                return ss;
            }
        }

        /// <summary>
        /// return string[]
        /// </summary>
        /// <param name="aa">string to be find</param>
        /// <param name="exp">express</param>
        /// <returns></returns>
        public string[] Matches(string aa, string exp)
        {
            var match = System.Text.RegularExpressions.Regex.Matches(aa, exp.Replace("*", "\\S+?"));
            List<string> lst = new List<string>();
            for (int i = 0; i < match.Count; i++)
            {
                lst.Add(match[i].Value);
            }
            return lst.ToArray();
        }

        public static void exportExcel(string excelFileName, System.Data.DataSet ds, string Pwd, bool isReadonly)
        {
            new EPReport().export(excelFileName, ds, Pwd, isReadonly);
        }

        public static void exportExcel(string excelFileName, System.Data.DataTable dt, string Pwd, bool isReadonly)
        {
            new EPReport().export(excelFileName, dt.DataSet, Pwd, isReadonly);
        }

    }
}
